import { createRouter, createWebHashHistory } from "vue-router";
import Home from "@/views/Home/Home.vue";

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home,
  },
  {
    path: "/sign",
    name: "Sign",
    component: () => import("@/views/Sign/index.vue"),
  },
  {
    path: "/visitor",
    name: "Visitor",
    component: () => import("@/views/Visitor/index.vue"),
  },
  {
    path: "/out",
    name: "Out",
    component: () => import("@/views/Out/index.vue"),
  },
  {
    path: "/visitorout",
    name: "VisitorOut",
    component: () => import("@/views/VisitorOut/index.vue"),
  },
  {
    path: "/fingerin",
    name: "FingerIn",
    component: () => import("@/views/Sign/FingerIn/index.vue"),
  },
  {
    path: "/facein",
    name: "FaceIn",
    component: () => import("@/views/Sign/FaceIn/index.vue"),
  },
  {
    path: "/fingerout",
    name: "FingerOut",
    component: () => import("@/views/Out/FingerOut/index.vue"),
  },
  {
    path: "/faceout",
    name: "FaceOut",
    component: () => import("@/views/Out/FaceOut/index.vue"),
  },
  {
    path: "/registerfinger/:id",
    name: "registerfinger",
    component: () => import("@/views/register/index.vue"),
  },
  {
    path: "/user",
    name: "user",
    component: () => import("@/views/user/index.vue"),
  },
];

const router = createRouter({
  history: createWebHashHistory(process.env.BASE_URL), //createWebHashHistory
  routes,
  scrollBehavior(to, from, savedPosition) {
    // savedPosition 会在你使用浏览器前进或后退按钮时候生效
    // 这个跟你使用 router.go() 或 router.back() 效果一致
    //这里主要处理当你的home滚动再底部，跳转页面也是底部的bug情况
    //主要是让页面回到顶部
    if (savedPosition) {
      return savedPosition;
    } else {
      return { x: 0, y: 0 };
    }
  },
});

export default router;
